package com.lzh.others.leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author by lzh
 * @Classname LeetCode822
 * @Description TODO
 * @Date 2022/2/6 19:24
 */
public class LeetCode822 {
    //理解：找到最小的与在正面不相同的数，首先排除正反两边都相同的卡片，
    //然后找到最小的数字，即可
    //方法1 Hash Set
    public static int flipgame(int[] fronts, int[] backs) {
        Set<Integer> same = new HashSet<>();
        for (int i = 0; i < fronts.length; i++) {
            if (fronts[i] == backs[i]) {
                same.add(fronts[i]);
            }
        }
        int ans = 9999;
        //循环获得正反面数字不相同的卡片
        for (int x : fronts) {
            if (!same.contains(x)) {
                ans = Math.min(ans, x);
            }
        }
        for (int x : backs) {
            if (!same.contains(x)) {
                ans = Math.min(ans, x);
            }
        }
        return ans % 9999;
    }

    public static void main(String[] args) {
        int[] fronts = {1, 2, 4, 4, 7};
        int[] backs = {1, 3, 4, 1, 3};
        int result = flipgame(fronts, backs);
        System.out.println(result);
    }
}
